package design.p3_singleton;

/**
 * @ClassName: Java
 * @description: 内部类单例
 * @author: zxf
 * @create: 2021-06-17 17:37
 **/
public class Singleton1 {

    private Singleton1(){}

    private static class SingleFactory{
        private static Singleton1 instance = new Singleton1();
    }

    public static Singleton1 getInstance(){
        return SingleFactory.instance;
    }

    public Object readResolve() {
        return getInstance();
    }
}
// 类加载过程是线程互斥的，静态内部类只会在第一次加载。



